package cn.simple.manager.web;

import cn.simple.manager.Repository.ImageStorageResponsitory;
import cn.simple.manager.todo.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/images")
public class ImageController {

    @Autowired
    private ImageStorageResponsitory imageStorageResponsitory;

    /**
     * 获取所有标签
     * @return
     */
    @RequestMapping("/tags")
    public ResponseEntity tagList(){
        return ResponseEntity.ok(imageStorageResponsitory.getTagGroupByName());
    }

    /**
     * 根据标签获取图片列表
     * @param tagName
     * @return
     */
    @RequestMapping("/tags/{tagName}")
    public ResponseEntity getTagImage(@PathVariable(value = "tagName",required = false) String tagName){
        if(StringUtils.isEmpty(tagName)){
            return ResponseEntity.ok(imageStorageResponsitory.findAll());
        }else{
            return ResponseEntity.ok(imageStorageResponsitory.selectTagImageStorage(tagName));
        }
    }


}
